<?php
/**
 * @desc Supposed to deal with ajax requests
 */
// Set Pat in $PATH
define('PATH', '/home/geoseobe/tinymce.sea-wasp.net/');

	class AjaxFunctions {
		
		CONST VERSION			= '0.1';
		CONST AUTOR				= 'Oliver Blum <ozycms@gmail.com>';
		CONST LAST_CHANGE		= '12.09.2007';
		CONST KLASSE			= 'AjaxFunctions';
		CONST DESC				= 'Supposed to deal with ajax requests';
		CONST LICENSE			= 'License [BSD] <http://www.opensource.org/licenses/bsd-license.php> </License.txt>';
		
		/**
		 * @return boolean
		 * @desc Works as a deflector and deflects the action to the right function.
		 */
		public function __construct(){
			$data = $_GET;
			if(is_array($data) && array_key_exists('action', $data)){
				switch($data['action']){
					case 'GetContentModul':
						self::GetContentModul($data);
					break;
				}
			}
			return FALSE;
		}
		
//----------------------
		/**
		 * @param string array $data
		 * @desc This is the content modul for normal content with text and images.
		 * @desc It generate a new instance of the tynmemce wysiwyg editor.
		 * @desc $data is the $_POST array
		 */
		private function GetContentModul($data){
			Header("Pragma: no-cache");
			Header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
			Header("Content-Type: text/php");
			// declaration
			$show		= NULL;
			$viewalias	= NULL;
			// temporary name dummy for the dom
			$set 	= time();
			
			if(is_array($data) && array_key_exists('modul', $data)){
				if(substr($data['modul'], 0,5) == 'view['){
					$viewalias		= $data['modul'];
					$data['modul'] 	= 'view';
				}
				print '
					<script type="text/javascript">
						sortable();
					</script>
				';
				switch($data['modul']){
					// ------------------------------
					case 'fulltext':
						// declare vars for dynamic unique ids
						$idid = 'list_'.time();
						$areaid = 'area'.$idid;
						print '
						<script type="text/javascript">
						tinyMCE.init({
						mode : "exact",
						theme : "advanced",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "bottom",
						theme_advanced_resizing : false,
						plugins : "safari,pagebreak,style,layer,table,save,spellchecker,advhr,advimage,advlink,iespell,inlinepopups,insertdatetime,preview,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
						// Theme options
						theme_advanced_buttons1 : "save, cut,copy|,search,replace, undo,redo,help,code,|,fullscreen,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontsizeselect",
						theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,link,unlink,anchor,image,cite,abbr,acronym,del,hr,removeformat,|,sub,sup,|,backcolor",
						theme_advanced_buttons3 : "tablecontrols,charmap,visualaid,template",
						theme_advanced_buttons3_add : "spellchecker",
						theme_advanced_toolbar_location : "top",
						theme_advanced_toolbar_align : "left",
						theme_advanced_statusbar_location : "bottom",
						theme_advanced_resizing : true,
						spellchecker_languages : "+English=en,German=de",
						file_browser_callback : "myFileBrowser",
						paste_auto_cleanup_on_paste : true,
						paste_insert_word_content_callback : "convertWord",
						apply_source_formatting : true,
						force_br_newlines : false,
						force_p_newlines : false,
						forced_root_block : "",
						invalid_elements : "",
						entity_encoding : "raw",
						relative_urls : true,
						cleanup : true,
						convert_fonts_to_spans : true,
						convert_newlines_to_brs : false,
						fix_list_elements : true,
						fix_table_elements : true,
						fix_nesting : true,
						elements : "'.$areaid.'",
						template_templates : [
							{
						title : "Image Text Combination [Left]",
						src : "jscripts/tiny_mce/plugins/template/image_text_combo_left.html",
						description : "An image [250*n] on the left hand with floating text."
							},
							{
						title : "Image Text Combination [Right]",
						src : "jscripts/tiny_mce/plugins/template/image_text_combo_right.html",
						description : "An image [250*n] on the right hand with floating text."
							}
						]
					
						});
							/** Drag and Drop Sortable */
							sortable();
						</script>
						';
						// Write List
						print '<li id="'.$idid.'">
						<div>
						<div class="clear" style="height: 20px;"> </div>
							<div class="table_head">
								<div style="float:left;"><h1>New Left Content Paragraph</h1></div>
								<div style="float: right;"> &#160;
								<img src="images/move.gif" style="border: none; cursor: pointer;" alt="Toogle" title="Toogle" onclick="Effect.toggle(\'hide'.$set.'\',\'appear\');" />
								<img src="images/delete.gif" style="border:none; cursor: pointer;" alt="" title=""  onclick="Modalbox.show($(\'conf'.$set.'\'), {title: this.title, width: 272}); return false;" />
								</div>
								<div class="clear"></div>
							</div>
							<div id="hide'.$set.'">
							<div class="table_td_left"><label for="headline">Headline</label></div>
							<div class="table_td_right" style="padding-right: 0; margin-top: -5px; padding-top: 0; width: 477px;"><input type="text" name="content[fulltext_'.$idid.'][headline]" id="headline" value="" style="width: 472px;" /></div>
						<div class="clear"></div>
							<textarea name="content[fulltext_'.$idid.'][content]" cols="2" rows="4" style="width:690px; height: 340px; background-color: #E3E3E0; margin-top: 4px;" id="'.$areaid.'"></textarea>
							<script type="text/javascript">
								/** tinyMCE.execCommand(\'mceAddControl\', true, \''.$areaid.'\');*/
							</script>
								<div class="clear">
									<a style="display: none;" href="javascript:void(0);" onclick="tinyMCE.execCommand(\'mceAddControl\', true, \''.$areaid.'\'); show_that(\'remove'.$set.'\'); hide_that(\'build'.$set.'\');"  id="build'.$set.'">[Generate TinyMCE Editor]</a>
									<a  href="javascript:void(0);" onclick="tinyMCE.execCommand(\'mceRemoveControl\',false,\''.$areaid.'\'); show_that(\'build'.$set.'\'); hide_that(\'remove'.$set.'\');" id="remove'.$set.'">[Remove TinyMCE Editor]</a>
									<br /><br />
								</div>			
							</div>
						</div>
							
						<div class="confirm" id="conf'.$set.'" style="display: none; background-image: url(images/confirm.gif); height: 109px; margin:0; padding: 0; width: 272px;">
						<br /><br /><div style="margin-left: 45px; font-weight: normal;">Delete this Module...?:</div>
						<br /><div style="text-align: center;"><input type="button" value="Yes" onclick="removeElement(\''.$areaid.'\',\''.$areaid.'\'); removeElement(\''.$idid.'\', \'\'); Modalbox.hide();" />  <input type="button" value="No" onclick="Modalbox.hide();" /></div>
						</div>
						
						<div style="width: 690px; height: 20px; background-color: #cccccc;">
						<b>New Content Module</b>
						</div>
						<div id="mochoice_'.$set.'">
						<div class="clear"></div>
						<div class="table_td_left"><div style="float: left;"><img src="images/help.gif" style="border: none;" title="Content-Modul: Take your Choice..." alt="Content-Modul: Take your Choice..." /></div><div style="float: left; line-height: 25px; margin-left: 2px; width: 80%;"> <label for="page_modulchose">Chose a Module</label></div> </div>
						<div class="table_td_right" style="padding-right: 0; width: 477px;">
						<select name="page_modulchose_'.$set.'" id="chose" onchange="GetNewMoul(\'aftershow'.$set.'\',this.options[this.selectedIndex].value, \'GetContentModul\',\'chose\', \''.$_REQUEST['tree'].'\', \''.$_REQUEST['nodeID'].'\'); this.selectedIndex=\'0\'; new Effect.ScrollTo(\'aftershow'.$set.'\', {offset: 50});" style=" background-color: #E3E3E0; margin-top: 2px;" size="1">
							<option value="">Chose a Module</option>
							<option value="fulltext">Content Paragraph</option>
						</select>
						</div>
						<div class="clear"></div>
						<div class="table_td_left"><div style="float: left;"></div><div style="float: left; line-height: 25px; margin-left: 2px; width: 80%;">
							<input type="submit" style="width: 120px; border: none; background: #996666; color: #ffffff; height: 22px;" name="Save" value="Save Content" onclick="Modalbox.show($(\'load'.time().'\'), {title: this.title, width: 128, height: 30, overlayClose: false});" />
							
							</div> </div>
							<div class="table_td_right" style="padding-right: 0; width: 477px;">
										
							</div>
							<div class="clear"></div>
						</li>
						<li style="list-style: none;"><div class="clear" id="aftershow'.$set.'"><a name="down'.$set.'" id="down'.$set.'"> &#160;</a> &#160;</div></li>
						';
						print $show;
					break;
				// ------------------------------
				}	
			}
			return FALSE;
		}
		
	//----------------------
}
	
$Move = new AjaxFunctions();


?>